package gameobj;

import render.Model;

/**
 * @author YOU友
 * @二作 Passerby
 * @说明
 * 所有的“活的”物体都属于这个类的子类，主要特征有：
 * 有血量，会攻击
 */
public abstract class Actor extends Character {
	private int health;
//	满血血量
	private int maxHealth;
//	攻击间隔
	private int attackSpeed = 5;
//	下一次攻击时间
	private int nextAttackTime = attackSpeed;
//	是否正在攻击
	private boolean isAttacking = false;
//  攻击力	
	private int attack = 1;
	
//	在Actor这里存储发射的子弹模型
	protected Model bulletModel = null;
	
	protected abstract void attack();

	public int getHealth() {
		return health;
	}

	public void setHealth(int health) {
		if (health < 0) {
			health = 0;
		}
		this.health = health;
	}
	
	public void setBulletModel(Model model) {
		bulletModel = model;
	}
	
	
	public boolean under_attack(Actor pk)
	{
		return this.getRectangle().intersects( pk.getRectangle() );
	}
	
	abstract public void getHurt (int damage);
	
	/**
	 * @author YOU友
	 * @说明
	 * 死亡的结算（包括死亡的动画播放控制）放这里
	 */
	public void death ()
	{
		this.setAlive(false);
	}
	
	public void setAttackSpeed(int attackSpeed) {
		this.attackSpeed = attackSpeed;
//		也将下次攻击时间重置为攻击速度
		this.nextAttackTime = attackSpeed;
	}
	
	public void setAttacking(boolean isAttacking) {
		this.isAttacking = isAttacking;
	}
	
	@Override
	public void ObjRun() {
		move();
//		如果到了下次攻击时间了
		if (--nextAttackTime <= 0 && isAttacking) {
			attack();
//			重置计时器
			nextAttackTime = attackSpeed;
		}
		
	}

	public int getMaxHealth() {
		return maxHealth;
	}

	public void setMaxHealth(int maxHealth) {
		this.maxHealth = maxHealth;
	}

	public int getAttack() {
		return attack;
	}

	public void setAttack(int attack) {
		this.attack = attack;
	}


	
}
